# Copyright (c) 2008-2009 Mikhail Chernov 
#
# This file is part of dcExplorer.
#
# dcExplorer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# dcExplorer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dcExplorer.  If not, see <http://www.gnu.org/licenses/>.

package dcExplorer::server::CommandQueue;
use strict;
use utf8;
use server::Command;

sub new
{
	my $proto = shift;
	my $class = ref($proto) || $proto;
	my $self = {};
	$self->{Commands} = [];
	bless ($self, $class);
	return $self;
}

sub enqueue
{
	my $self = shift;
	my $action = shift;
	push @{$self->{Commands}}, $action;
}

sub getXML
{
	my $self = shift;
	my $xml = '<x-dc-perform>';
	my $i = 0;
	for my $command (@{$self->{Commands}})
	{
		$xml .= $command->getXML(++$i);
	}
	$xml .= '</x-dc-perform>';
	return $xml;
}

sub size
{
	my $self = shift;
	return scalar @{$self->{Commands}};
}

sub clear
{
	my $self = shift;
	$self->{Commands} = [];
}

1;
